package cn.gok.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author: chen fan
 * @since: 2022/11/15 17:41
 * @description:
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    /**
     * 设置添加数据时，字段的填充策略
     */
    @Override
    public void insertFill(MetaObject metaObject) {

       this.setFieldValByName("createTime",new Date(), metaObject);
       this.setFieldValByName("updateTime",new Date(), metaObject);
    }
    /**
     * 设置修改数据时，字段的填充策略
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime",new Date(), metaObject);
    }
}
